package mc747.portal.logicas;

import home.axis2.testcase.EnderecosServiceLocator;
import home.axis2.testcase.EnderecosServicePortType;
import home.axis2.testcase.xsd.Endereco;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mc747.portal.servlet.Logica;

public class GetCEP implements Logica {

	public void executa(HttpServletRequest req, HttpServletResponse res)
			throws Exception {
		String cep = req.getParameter("cep");
		EnderecosServicePortType end = new EnderecosServiceLocator().getEnderecosServiceHttpSoap11Endpoint();
		res.setContentType("json");
		Endereco endereco =  end.getEndereco(cep);
		String json = "{" +
				"\"bairro\":\"" + endereco.getBairro() + "\"," +
				"\"cidade\":\"" + endereco.getCidade() + "\"," +
				"\"estado\":\"" + endereco.getEstado() + "\"," +
				"\"logradouro\":\"" + endereco.getLogradouro() + "\"" +
						"}";
		res.getOutputStream().println(json);
		
	}

}
